package com.bj.dz.service.impl;

import com.bj.dz.entity.WatersupplyBackbonedata;
import com.bj.dz.mapper.WatersupplyBackbonedataMapper;
import com.bj.dz.service.WatersupplyBackbonedataService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class WatersupplyBackbonedataServiceImpl implements WatersupplyBackbonedataService {

    @Resource
    private WatersupplyBackbonedataMapper watersupplyBackbonedataMapper;

    public WatersupplyBackbonedata getWatersupplyBackbonedataById(Integer id){
        return watersupplyBackbonedataMapper.getWatersupplyBackbonedataById(id);
    }

    public List<WatersupplyBackbonedata>	getWatersupplyBackbonedataListByMap(Map<String,Object> param){
        return watersupplyBackbonedataMapper.getWatersupplyBackbonedataListByMap(param);
    }

    public Integer getWatersupplyBackbonedataCountByMap(Map<String,Object> param){
        return watersupplyBackbonedataMapper.getWatersupplyBackbonedataCountByMap(param);
    }

    @Transactional
    public boolean addWatersupplyBackbonedata(WatersupplyBackbonedata watersupplyBackbonedata){
            return watersupplyBackbonedataMapper.insertWatersupplyBackbonedata(watersupplyBackbonedata)>0?true:false;
    }

    @Transactional
    public boolean modifyWatersupplyBackbonedata(WatersupplyBackbonedata watersupplyBackbonedata){
        return watersupplyBackbonedataMapper.updateWatersupplyBackbonedata(watersupplyBackbonedata)>0?true:false;
    }

    @Transactional
    public boolean deleteWatersupplyBackbonedataById(Integer id){
        return watersupplyBackbonedataMapper.deleteWatersupplyBackbonedataById(id)>0?true:false;
    }

    public Page<WatersupplyBackbonedata> queryWatersupplyBackbonedataPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = watersupplyBackbonedataMapper.getWatersupplyBackbonedataCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<WatersupplyBackbonedata> watersupplyBackbonedataList = watersupplyBackbonedataMapper.getWatersupplyBackbonedataListByMap(param);
        page.setRows(watersupplyBackbonedataList);
        return page;
    }

}
